﻿using AxWMPLib;
using MiniBlinkPinvoke;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace WallPapper
{
    public partial class FormPapper : Form
    {
        public int model { get; set; }

        public string path { get { return _path; } set {
                _path = value;
                if (model == 0)
                    (Tag as AxWindowsMediaPlayer).URL = _path;
                else if(model == 1)
                    (Tag as BlinkBrowser).Url = _path;
                else if (model == 2)
                    (Tag as PictureBox).ImageLocation = _path;
            } }

        private string _path { get; set; }

        public FormPapper(int model, String path)
        {
            InitializeComponent();
            ControlAdded += (x,y)=> {
                (x as Control).Click += (c, v) => {
                    MessageBox.Show("Test");
                };
            };
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPapper));
            if (model == 0)//视频壁纸
            {
                AxWindowsMediaPlayer axWindowsMediaPlayer1 = new AxWindowsMediaPlayer();
                axWindowsMediaPlayer1.BeginInit();
                axWindowsMediaPlayer1.Dock = System.Windows.Forms.DockStyle.Fill;
                axWindowsMediaPlayer1.Enabled = true;
                axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 0);
                axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
                axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
                axWindowsMediaPlayer1.Size = new System.Drawing.Size(800, 450);
                axWindowsMediaPlayer1.TabIndex = 0;
                Controls.Add(axWindowsMediaPlayer1);
                axWindowsMediaPlayer1.EndInit();
                axWindowsMediaPlayer1.uiMode = "none";
                axWindowsMediaPlayer1.URL = AppDomain.CurrentDomain.BaseDirectory + "demo.mp4";
                axWindowsMediaPlayer1.settings.setMode("loop", true);
                Tag = axWindowsMediaPlayer1;
            }
            else if (model == 1)
            {
                MiniBlinkPinvoke.BlinkBrowser blink = new MiniBlinkPinvoke.BlinkBrowser();
                blink.Dock = DockStyle.Fill;
                blink.Url = "file:///" + AppDomain.CurrentDomain.BaseDirectory + "demo.html";
                Tag = blink;
                Controls.Add(blink);
            }
            else if (model == 2)
            {
                PictureBox pic = new PictureBox();
                pic.Dock = DockStyle.Fill;
                pic.ImageLocation = AppDomain.CurrentDomain.BaseDirectory + "demo.png";
                pic.SizeMode = PictureBoxSizeMode.CenterImage;
                Tag = pic;
                Controls.Add(pic);
            }
            this.model = model;
            this.path = path;
            this.FormBorderStyle = FormBorderStyle.None;
            this.Location = new Point(0, 0);
            this.Left = 0;
            this.Padding = new Padding(0);
            this.Top = 0;

            this.Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
            this.Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
            this.WindowState = FormWindowState.Normal;
            this.AutoScaleMode = AutoScaleMode.None;
            this.TopMost = true;
            Screen screen = Screen.FromHandle(this.Handle);
            this.MaximumSize = new Size(screen.Bounds.Width, screen.Bounds.Height);
            this.WindowState = FormWindowState.Maximized;
            Win32API.SetParent(this.Handle, Win32API.GetWorkerW());
        }

    }
}
